import React,{useState,useMemo} from 'react'

export default function Sum() {
  const [firstNum,setFirstNum]=useState(10)
  const[secondNum,setSecondNum]=useState(20)
  const sum=useMemo(()=>{
    return firstNum+secondNum
  },[firstNum,secondNum])
  return (
    <div>
        <h1>结果:{firstNum}+{secondNum}={sum}</h1>
        <button onClick={()=>{setFirstNum(firstNum+1)}}>firstNum+1</button>
        <button onClick={()=>{setSecondNum(secondNum+5)}}>secondNum+5</button>
    </div> 
  )
}
